package com.zymail.service.impl;

import com.zymail.bean.ZyClass;
import com.zymail.mapper.ZyClassMapper;
import com.zymail.service.ZyClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dorado
 * @since 2021-04-12
 */
@Service
public class ZyClassServiceImpl extends ServiceImpl<ZyClassMapper, ZyClass> implements ZyClassService {

    @Autowired
    public ZyClassService classService;

    @Override
    public List<ZyClass> getSortedClass() {
        List<ZyClass> classList =  classService.list();
        //将排列变成有序
        for(int i = 0; i < classList.size(); i++){
            ZyClass current = classList.get(i);
            if(current.getFaId().equals(current.getId())) continue;

            classList.remove(i);
            int index = 0;
            for(; index < classList.size(); index++){
                if(current.getFaId().equals(classList.get(index).getId())){
                    break;
                }
            }

            if(index == classList.size()){
                classList.add(current);
            }else{
                classList.add(index + 1, current);
            }

        }
        return classList;
    }
}
